package tech.aistar.mapper.massage;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tech.aistar.entity.massage.Massage;

import java.util.List;

public interface MassageMapper {

    //查出未读(帖子)的
    @Select("select * from massage where re_id = #{value} and m_type=0 and m_status = 0")
    List<Massage> findUnReadPost(Integer reId);
    //根据用户id未读查出 回复他评论用户(评论的commit_id)
    @Select("select * from massage where re_id = #{value} and m_type=1 and m_status = 0")
    List<Massage> findUnReadCom(Integer reId);

    //根据用户id查出 评论 它的用户(帖子的post_id)
    @Select("select * from massage where re_id = #{value} and m_type=0")
    List<Massage> findUidAndPost(Integer reId);

    //根据用户id查出 回复他评论用户(评论的commit_id)
    @Select("select * from massage where re_id = #{value} and m_type=1")
    List<Massage> findUidAndCom(Integer reId);

    //根据用户id查出点赞的帖子
    @Select("select * from massage where re_id = #{value} and m_type=2")
    List<Massage> findUidZpost(Integer reId);

    //根据用户id查出点赞的评论
    @Select("select * from massage where re_id = #{value} and m_type=3")
    List<Massage> findUidAndZCom(Integer reId);

    //根据用户id查出 点赞 它的用户(动态的pic_id)
    @Select("select * from massage where re_id = #{value} and m_type=4")
    List<Massage> findPicZan(Integer reId);

    //添加评论(帖子的)
    @Insert("insert into massage values(#{mId},#{uId},#{uName},0,#{reId},#{reName},#{content},null,#{postId},null,now(),0)")
    void addPostMassage(Massage massage);

    //添加回复(评论)
    @Insert("insert into massage values(#{mId},#{uId},#{uName},1,#{reId},#{reName},#{content},#{commitId},null,null,now(),1)")
    void addComMassage(Massage massage);


    //添加点赞(帖子)
    @Insert("insert into massage values(#{mId},#{uId},#{uName},2,#{reId},#{reName},#{content},null,#{postId},null,now(),0)")
    void addPostZan(Massage massage);

    //添加点赞(评论)
    @Insert("insert into massage values(#{mId},#{uId},#{uName},3,#{reId},#{reName},#{content},#{commitId},null,null,now(),0)")
    void addComZan(Massage massage);

    //添加点赞(动态)
    @Insert("insert into massage values(#{mId},#{uId},#{uName},4,#{reId},#{reName},#{content},null,null,#{picId},now(),0)")
    void addPicZan(Massage massage);

    //update collections set collect_status = 1 where id = #{id} and kind_id = #{kindId}
    //消息中心删除消息
    @Update("update massage set m_status = 2 where m_id=#{mId}")
    void delMassage(@Param("mId") Long mId , @Param("uId") Integer uId);

    //消息中心查看消息 设为1表示已查看
    @Update("update massage set m_status = 1 where m_id=#{value}")
    void ViewMassage(Long mId);





}
